package com.douyuehan.doubao.wechatpay.jparepository;

import com.douyuehan.doubao.wechatpay.model.entity.Customers;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public interface CustomerRepository extends JpaRepository<Customers, Long> {


    @Query(value = "select * from kp_customers p where p.id_card=?1 and p.project_id=?2", nativeQuery=true)
    List<Customers> findByIdCard(String idCard, long projectId);

    @Query(value = "select p.is_snap_up from kp_customers p where p.id=?1 and p.project_id=?2", nativeQuery=true)
    Integer findIsSnapUpById(long userId, long projectId);

    @Query(value = "select * from kp_customers p where p.customer_phone=?1 and p.project_id=?2", nativeQuery=true)
    List<Customers> findListByTelephone(String telephone, long projectId);

    @Query(value = "select * from kp_customers p where p.id_card=?1 and p.project_id=?2", nativeQuery=true)
    List<Customers> findpayOutTradeNoByIdCard(String idCard, long projectId);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update kp_customers set is_snap_up=0 where project_id=?1 and id=?2", nativeQuery=true)
    Integer updateIsSnapUpById(long projectId, long customerId);

    @Query(value = "select p.contractnull_img from parking_project p where id=?1", nativeQuery=true)
    String findcontractnullImg(long projectId);

    @Query(value = "select p.contracttitle_img from kp_customers p where project_id=?1 and id=?2", nativeQuery=true)
    String findcontracttitleImg(long projectId, long customerId);

    @Query(value = "select * from kp_customers p where p.id=?1 and p.project_id=?2", nativeQuery=true)
    Customers findByIdAndProjectId(long Id, long projectId);

    @Query(value = "select * from kp_customers p where p.id=?1 and p.project_id=?2", nativeQuery=true)
    List<Customers> findpayMoneyOrPayNumber(Long id, long projectId);



}
